using System;
using Microsoft.Practices.PageFlow;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeWeb;
using System.Web;
using PageFlow.Util;

namespace TestWCSFSitemaps.Statements
{
    public class StatementsController : IStatementsController
    {
        private const string INPUT_TEXT = "inputText";

        private IPageFlowProvider provider;
        private IPageFlowUtil pageFlowUtil;
        private IPageFlow pageFlow;

        [InjectionConstructor]
        public StatementsController([ServiceDependency]IPageFlowUtil pageFlowUtil,
            [ProviderDependency(typeof(PageFlowDirectory))]IPageFlowProvider pageflowProvider)
        {
            this.pageFlowUtil = pageFlowUtil;
            this.provider = pageflowProvider;
        }

        private IPageFlow StatementsPageFlow
        {
            get 
            {
                if (pageFlow == null && provider != null)
                    pageFlow = provider.GetPageFlow(typeof(Statements.PageFlows.StatementsPageFlow));

                return pageFlow;
            }
        }

        public void Abort()
        {
            pageFlowUtil.Abort(StatementsPageFlow);
        }

        public void StartPageFlow()
        {
            pageFlowUtil.EnsureCurrentPage(StatementsPageFlow, SiteMap.CurrentNode.Key);
        }

        public void GoSeeX()
        {
            pageFlowUtil.Navigate(StatementsPageFlow, "goSeeX");
        }

        public void GoSeeY()
        {
            pageFlowUtil.Navigate(StatementsPageFlow, "goSeeY");
        }

        public void GoSeeZ()
        {
            pageFlowUtil.Navigate(StatementsPageFlow, "goSeeZ");
        }

        public void CompletePageFlow()
        {
            pageFlowUtil.Complete(StatementsPageFlow);
        }

        public void StoreText(string text)
        {
            StatementsPageFlow.UserData[INPUT_TEXT] = text;
        }

        public string GetText()
        {
            return StatementsPageFlow.UserData[INPUT_TEXT].ToString();
        }
    }
}
